Skip to content

Fix numpy 2.4.0 compatibility in create_violin()#5483

Merged
camdecoster merged 5 commits intoplotly:mainfrom
Mr-Neutr0n:fix-numpy-percentile-issue-5461
Mar 18, 2026
Merged

Fix numpy 2.4.0 compatibility in create_violin()#5483
camdecoster merged 5 commits intoplotly:mainfrom
Mr-Neutr0n:fix-numpy-percentile-issue-5461

Conversation

@Mr-Neutr0n
Copy link
Contributor

Summary

Fixes #5461

The interpolation parameter was deprecated in numpy.percentile() and removed in numpy 2.4.0. It has been replaced with the method parameter which uses the same values.

Problem

create_violin() fails with numpy 2.4.0:

TypeError: percentile() got an unexpected keyword argument 'interpolation'

Solution

Changed all three np.percentile() calls in calc_stats() from using interpolation to method:

  • interpolation="linear"method="linear"
  • interpolation="lower"method="lower"
  • interpolation="higher"method="higher"

Changes

Modified plotly/figure_factory/_violin.py:

# Before
q2 = np.percentile(x, 50, interpolation="linear")
q1 = np.percentile(x, 25, interpolation="lower")
q3 = np.percentile(x, 75, interpolation="higher")

# After
q2 = np.percentile(x, 50, method="linear")
q1 = np.percentile(x, 25, method="lower")
q3 = np.percentile(x, 75, method="higher")

Test plan

import plotly.figure_factory as ff
fig = ff.create_violin(data=[1, 2, 3, 4, 5])
fig.show()  # Should work without error

Or run the existing test:

pytest tests/test_optional/test_figure_factory/test_figure_factory.py::TestViolin::test_violin_fig

🤖 Generated with Claude Code

Fixes plotly#5461

The 'interpolation' parameter was deprecated in numpy.percentile() and
removed in numpy 2.4.0. It has been replaced with the 'method' parameter
which uses the same values.

Changed all three np.percentile() calls in calc_stats() from using
'interpolation' to 'method'.
@camdecoster camdecoster self-assigned this Feb 6, 2026
@camdecoster
Copy link
Contributor

Thank you for the PR. I'll take a look and follow up.

Copy link
Contributor

@camdecoster camdecoster left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. I added a minimum version requirement for numpy and added a changelog entry. Thanks for your contribution!

@camdecoster camdecoster merged commit b009b25 into plotly:main Mar 18, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: create_violin() failure with numpy==2.4.0: TypeError: percentile() got an unexpected keyword argument 'interpolation'

2 participants